package org.stephen.recommend.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

public class Utils {
	public static boolean isEmpty(Object obj) {
		if (obj == null) {
			return true;
		} else {
			if (obj instanceof String) {
				String instance = (String) obj;
				if (instance.trim().length() <= 0 || "null".equalsIgnoreCase(instance)) {
					return true;
				}
			} else if (obj instanceof Integer) {
				Integer instance = (Integer) obj;
				if (instance < 0) {
					return true;
				}
			} else if (obj instanceof Collection) {
				Collection<?> instance = (Collection) obj;
				if (instance.size() <= 0) {
					return true;
				}
			} else if (obj instanceof Map) {
				Map<?, ?> instance = (Map) obj;
				if (instance.size() <= 0) {
					return true;
				}
			} else if (obj instanceof Object[]) {
				Object[] instance = (Object[]) ((Object[]) obj);
				if (instance.length <= 0) {
					return true;
				}
			} else if (obj instanceof Long) {
				Long instance = (Long) obj;
				if (instance < 0L) {
					return true;
				}
			}

			return false;
		}
	}

	public static boolean isNotEmpty(Object obj) {
		return !isEmpty(obj);
	}

	public static <T> List<T> removeDuplicate(List<T> list) {
		return new ArrayList(new HashSet(list));
	}
}